/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databeans;

import beans.*;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.sql.rowset.CachedRowSet;
import utils.CargarConfiguraciones;

/**
 *
 * @author Eduardo Cerritos
 */
public class MateriaDocenteDataBean {
    private CachedRowSet rowSet;
    private CargarConfiguraciones cc;

    public MateriaDocenteDataBean() throws Exception{
        cc = new CargarConfiguraciones();
        Class.forName(cc.getValor("driver"));
        rowSet = new CachedRowSetImpl();
        rowSet.setUrl(cc.getValor("urlbase"));
        rowSet.setUsername(cc.getValor("usuario"));
        rowSet.setPassword(cc.getValor("clave"));
    }

    public void borrarMateriaDocente(String codigo, String codMateria) throws SQLException{

    String sql ="delete from docente_materia " +
            "where " +
            "codigo='"+codigo+"' " +
            "and codmateria = '"+codMateria+"'";
        rowSet.setCommand(sql);
        rowSet.execute();


}

    public void setMateriasDocente (ArrayList <DocenteMateriaBean> materias_docente) throws SQLException
    {

        Iterator it = materias_docente.iterator();
        while(it.hasNext()){
             DocenteMateriaBean aux= (DocenteMateriaBean) it.next();

             String sql="INSERT INTO docente_materia (" +
                                "codigo, " +
                                "codmateria)" +

                        "VALUES (" +
                                "'" + aux.getCodigo() + "'," +
                                "'" + aux.getCodmateria() + "')";
                rowSet.setCommand(sql);
                rowSet.execute();
        }
    }
}
